# -*- coding:utf-8 -*-


import os
from openpyxl import load_workbook

class RdExcel:

    def __init__(self, filepath=None):
        if filepath is not None:
            excelpath = filepath
        else:
            excelpath = os.getcwd() + u"\\inputdata\\权利人类型.xlsx"
        self.book = load_workbook(excelpath)

    # 获取一行加入LIST中
    def getCaseByExcel(self, type, caseNo=None):
        work_sheet = self.book.get_sheet_by_name(type)
        listRES = []

        for col in range(1, work_sheet.max_column + 1):
            listCOL=[]
            for row in range(1, work_sheet.max_row + 1):
                listCOL.append(work_sheet.cell(row=row, column=col).value)
            listRES.append(listCOL)

        return listRES

    # 获取整个Sheet组成[dist1,dist2]
    def getUserCaseByExcel(self,type):
        work_sheet = self.book.get_sheet_by_name(type)
        listRES = []

        for col in range(2, work_sheet.max_column + 1):
            dist = {}
            for row in range(1, work_sheet.max_row + 1):
                dist[work_sheet.cell(row=row, column=1).value] = work_sheet.cell(row=row, column=col).value
            listRES.append(dist)

        return listRES

    # 获取一行加入DIST中,方便遍历
    def getTypeCaseFromTypeNO(self,type,typeNO=None):
        count = 0
        dist ={}

        work_sheet = self.book.get_sheet_by_name(type)

        for i in range(1, work_sheet.max_column + 1):
            if typeNO == work_sheet.cell(row=1, column=i).value:
                count = i

        for j in range(1, work_sheet.max_row + 1):
            dist[work_sheet.cell(row=j, column=1).value]=work_sheet.cell(row=j, column=count).value

        return dist

    # 获取流程测试用例
    def getWorkFlowByExcel(self, type):
        work_sheet = self.book.get_sheet_by_name(type)
        listRES = []

        for row in range(2, work_sheet.max_row + 1):
            listROW = []
            for col in range(1,work_sheet.max_column + 1):
                listROW.append(work_sheet.cell(row=row, column=col).value)
            listRES.append(listROW)
        return listRES




if __name__ == "__main__":
    #print(os.getcwd())
    os.chdir("..//inputdata")
    a = RdExcel(os.getcwd()+"\\"+"权利人类型.xlsx")
    print(a.getUserCaseByExcel("法人机构"))


